/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aviso.entity;

import java.util.Calendar;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

/**
 *
 * @author avgusti
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "AdvertQuery.lookUpInBounds", query = "select a from AdvertQuery a where "
    + ":lat>=a.lats and :lat<=a.latn and "
    + ":lng>=a.lngw and :lng<=a.lnge"),
    @NamedQuery(name = "AdvertQuery.lookUpInBoundsByUser", query = "select a from AdvertQuery a where "
    + ":lat>=a.lats and :lat<=a.latn and "
    + ":lng>=a.lngw and :lng<=a.lnge and"
    + ":userid=a.user.id"),
    @NamedQuery(name = "AdvertQuery.lookUpByUser", query = "select a from AdvertQuery a where "
    + ":userid=a.user.id")
})
// @NamedQuery(name = "Advert.lookUp", query = "select a from Advert a where "
//    + "(a.lat>=:latw AND a.lat<=:late AND"
//    + "a.lng>=:lngs AND a.lng<=:lngn) AND"
//    + "(a.type:=:type OR 0=:type) AND"
//    + "(a.floor >=:minfloor AND a.floor<=:maxfloor) AND"
//    + ""
//    + "")
public class AdvertQuery extends ListWraper{

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @NotNull
    //private String address;
    private Double lats, latn, lnge, lngw;
    private int zoom;
    @NotNull
    private AdvType type = AdvType.APPARTMENT;
    private int floors = 0, floormin = 0, floormax = 0;
    private boolean floorfirst = true, floorlast = true;
    private int total_sqrmin = 0, total_sqrmax = 0,
            kitchen_sqrmin = 0,kitchen_sqrmax = 0,
            living_sqrmin = 0, living_sqrmax =0, 
            balkony_sqrmin = 0,balkony_sqrmax = 0;
    //0 all, 4 - [4-endless], -1 - room in appartment
    private int room_count = 0;
    private int pricemin = 0, pricemax = 0;
    public static final double grouping_range = 0.0001;
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar added_Date;
    @Temporal(TemporalType.DATE)
    private Calendar expire_Date;
    @Temporal(TemporalType.DATE)
    private Calendar expire_adv_Date;
    private boolean advertised;
    private String notes;
    @ManyToOne
    private UserName user;

    public int getBalkony_sqrmax() {
        return balkony_sqrmax;
    }

    public void setBalkony_sqrmax(int balkony_sqrmax) {
        this.balkony_sqrmax = balkony_sqrmax;
    }

    public int getKitchen_sqrmax() {
        return kitchen_sqrmax;
    }

    public void setKitchen_sqrmax(int kitchen_sqrmax) {
        this.kitchen_sqrmax = kitchen_sqrmax;
    }

    public int getLiving_sqrmax() {
        return living_sqrmax;
    }

    public void setLiving_sqrmax(int living_sqrmax) {
        this.living_sqrmax = living_sqrmax;
    }

    
    
    public int getZoom() {
        return zoom;
    }

    public void setZoom(int zoom) {
        this.zoom = zoom;
    }
    
    public Calendar getAdded_Date() {
        return added_Date;
    }

    public void setAdded_Date(Calendar added_Date) {
        this.added_Date = added_Date;
    }

    public boolean isAdvertised() {
        return advertised;
    }

    public void setAdvertised(boolean advertised) {
        this.advertised = advertised;
    }

   

    public int getBalkony_sqrmin() {
        return balkony_sqrmin;
    }

    public void setBalkony_sqrmin(int balkony_sqrmin) {
        this.balkony_sqrmin = balkony_sqrmin;
    }

    public Calendar getExpire_Date() {
        return expire_Date;
    }

    public void setExpire_Date(Calendar expire_Date) {
        this.expire_Date = expire_Date;
    }

    public Calendar getExpire_adv_Date() {
        return expire_adv_Date;
    }

    public void setExpire_adv_Date(Calendar expire_adv_Date) {
        this.expire_adv_Date = expire_adv_Date;
    }

    public boolean isFloorfirst() {
        return floorfirst;
    }

    public void setFloorfirst(boolean floorfirst) {
        this.floorfirst = floorfirst;
    }

    public boolean isFloorlast() {
        return floorlast;
    }

    public void setFloorlast(boolean floorlast) {
        this.floorlast = floorlast;
    }

    public int getFloormax() {
        return floormax;
    }

    public void setFloormax(int floormax) {
        this.floormax = floormax;
    }

    public int getFloormin() {
        return floormin;
    }

    public void setFloormin(int floormin) {
        this.floormin = floormin;
    }

    public int getFloors() {
        return floors;
    }

    public void setFloors(int floors) {
        this.floors = floors;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public int getKitchen_sqrmin() {
        return kitchen_sqrmin;
    }

    public void setKitchen_sqrmin(int kitchen_sqrmin) {
        this.kitchen_sqrmin = kitchen_sqrmin;
    }

    public int getLiving_sqrmin() {
        return living_sqrmin;
    }

    public void setLiving_sqrmin(int living_sqrmin) {
        this.living_sqrmin = living_sqrmin;
    }

    public Double getLatn() {
        return latn;
    }

    public void setLatn(Double latn) {
        this.latn = latn;
    }

    public Double getLats() {
        return lats;
    }

    public void setLats(Double lats) {
        this.lats = lats;
    }

    public Double getLnge() {
        return lnge;
    }

    public void setLnge(Double lnge) {
        this.lnge = lnge;
    }

    public Double getLngw() {
        return lngw;
    }

    public void setLngw(Double lngw) {
        this.lngw = lngw;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public int getPricemax() {
        return pricemax;
    }

    public void setPricemax(int pricemax) {
        this.pricemax = pricemax;
    }

    public int getPricemin() {
        return pricemin;
    }

    public void setPricemin(int pricemin) {
        this.pricemin = pricemin;
    }

    public int getRoom_count() {
        return room_count;
    }

    public void setRoom_count(int room_count) {
        this.room_count = room_count;
    }

    public int getTotal_sqrmax() {
        return total_sqrmax;
    }

    public void setTotal_sqrmax(int total_sqrmax) {
        this.total_sqrmax = total_sqrmax;
    }

    public int getTotal_sqrmin() {
        return total_sqrmin;
    }

    public void setTotal_sqrmin(int total_sqrmin) {
        this.total_sqrmin = total_sqrmin;
    }

    public AdvType getType() {
        return type;
    }

    public void setType(AdvType type) {
        this.type = type;
    }

    public UserName getUser() {
        return user;
    }

    public void setUser(UserName user) {
        this.user = user;
    }

    public Bounds getBounds() {
        return new Bounds(lats, latn, lnge, lngw);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }
    
    @Override
    public boolean  equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof AdvertQuery)) {
            return false;
        }
        AdvertQuery other = (AdvertQuery) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "aviso.entity.Advert[ id=" + id + " ]";
    }
}
